package com.ying.dogying.config;

import com.ying.dogying.im.MessageHandlerFactory;
import com.ying.dogying.im.ServerStartup;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

@Configuration
public class ImServerConfig {
	private static Logger log = LoggerFactory.getLogger(ImServerConfig.class);
    // 启动tio服务

    // 初始化消息处理器

    @Value("${im.server.port}")
    private Integer imPort;

    @Bean
    public ServerStartup serverStartup() {
        try {
            // 启动tio服务
            ServerStartup serverStartup = new ServerStartup(imPort);
            serverStartup.start();

            // 初始化消息处理器工厂
            MessageHandlerFactory.init();

            log.info("================= im server started ! =================");
            return serverStartup;
        } catch (IOException e) {
            log.error("im server 启动失败", e);
        }
        return null;
    }
}
